package com.chixing.day10_hashcode_exception.home;

public class EncryptUtil {
    //加密
    public static String encrypt(String str){
        String B = str.substring(1, str.length()) +str.substring(0, 1);

        char arr[] = B.toCharArray();
        int index = 0;
        for (int i = 0; i < B.length(); i++) {
            arr[index++] = (char) (B.codePointAt(i) + 3);

        }
            return new String(arr);

    }
//解密
    public static String decrypt(String src){
            String g=src.substring(src.length()-1,src.length())+src.substring(0,src.length()-1);
            char arr2[]=g.toCharArray();
            int index2=0;
            for (int i=0;i<arr2.length;i++){
                arr2[index2++]= (char) (g.codePointAt(i)-3);
//            arr2[i] -=3;
            }

        return new String(arr2);

    }

    public static void main(String[] args) {
        System.out.println(encrypt("hello"));
        System.out.println(decrypt("olleh"));
//优惠券
        String word= "1Ct3r4ip_ti4C6k9Et^";
        StringBuilder builder=new StringBuilder();
        for (int i = 0; i < word.length(); i++) {
            if (!(word.charAt(i) >= '0' && word.charAt(i) <= '9') ){
                builder.append(word.charAt(i) );

            }
        }
        System.out.print(builder);
    }
}
